﻿
using MediatR;
using Production_Get.API.API.Application.Commands.Procurement;
using Production_Get.API.Infrastructures.Interfaces;
using Return.Enum;
using SlaughterItem.Common.Infrastructures.Interfaces;
using THE_WIND_RISES.Common.Domans.Produce.Procurement;
using THE_WIND_RISES.Common.Domans.Produce.Resources;
using THE_WIND_RISES.Common.Domans.Produce.WorkCenter_;
using THE_WIND_RISES.Common.Dtos;


namespace Production_Get.API.Application.Commands.Procurement
{
    public class PaymentPlansShowHandler : IRequestHandler<PaymentPlansShowCommand, Result>
    {
        private readonly IBaseRepositoryGet<PaymentPlans> PaymentPlansRepository;
        private readonly ILogger<PaymentPlansShowHandler> logger;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="OrderLinesRepository"></param>
        public PaymentPlansShowHandler(ILogger<PaymentPlansShowHandler> logger, IBaseRepositoryGet<PaymentPlans> PaymentPlansRepository)
        {
            this.logger = logger;
            this.PaymentPlansRepository = PaymentPlansRepository;
        }
        public async Task<Result> Handle(PaymentPlansShowCommand request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCodes.Added };
            try
            {
                string sql= $"select * from PaymentPlans WHERE PurchasinId = {request.PurchasinId}";
                var list = PaymentPlansRepository.GetAll(sql, default);
                if (list!=null)
                {
                    result.Code = (int)CommonErrorCodes.Success;
                    result.Data = list;
                    result.Msg = "显示成功";
                }
                else
                {
                    result.Code = (int)CommonErrorCodes.Search;
                    result.Data = null;
                    result.Msg = "显示失败";
                    logger.LogError($"显示订单行信息失败");
                }
            }
            catch (Exception ex)
            {
                logger.LogError($"显示付款计划信息失败,错误信息为：" + ex.Message);
                throw;
            }
            return result;
        }
    }
}
